<!-- 考试动态 -->
<template>
    <div class="bg">
        <div class="title">
            <span>CIFA考试动态</span> 
        </div>
        <div class="content">
            <div class="left">
                <ul>
                    <li v-for="item in cawData" :key="item.id">
                        <div class="time">
                            <p v-text="dayjs(item.createTime).format('YYYY-MM')"></p>
                            <p v-text="dayjs(item.createTime).format('DD')"></p>
                        </div>
                        <img :src="item.image" />
                        <div class="txt">
                            <ul>
                                <li >
                                    <p v-text="item.name" ></p>

                                    <p v-text="item.intro"></p>
                                     <el-button plain class="detial" @click="detial(item.id)">详情</el-button>
                                </li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="right">
                <el-divider content-position="left">热点关注</el-divider>
                <ul>
                    <li v-for="item in newTopicData" :key="item.id"  >
                       <a v-text="item.name" @click="detial(item.id)" class="aa"></a>
                    </li>

                </ul>
            </div>

        </div>
        <el-pagination background layout="prev, pager, next" v-model:current-page="currentPage"
        @current-change="handelCurrentChange" :total="total" />    </div>
</template>
<script setup lang="ts">
import {cawListApi} from '@/api/exam/index'
import type { CawModel,CawParam } from '@/api/exam/index';
import dayjs from 'dayjs';
    const cawParam=ref<CawParam>({
    pageNum:1,
    pageSize:10,
    type:1,
    isTopic:''
})
const cawData=ref<CawModel[]>([])
    const currentPage = ref<number>(1)

const total=ref<number>(0)
onMounted(()=>{
    getDataLists()
    topicData()
})
const newTopicData=ref<CawModel[]>([])
async function topicData(){
    cawParam.value.isTopic=1
    const res= await  cawListApi(cawParam.value)
    if(res.code===200){
        newTopicData.value = res.data?.records ?? []
        }else{
            ElMessage.error(res.msg)
    }
}


async function getDataLists(){
 const res= await  cawListApi(cawParam.value)
 console.log('res',res)
 if(res.code===200){
        cawData.value = res.data?.records ?? []
        total.value = res.data?.total ?? 0
        currentPage.value = res.data?.current ?? 1
     
        }else{
            ElMessage.error(res.msg)
        }
}

function handelCurrentChange(pageNum: number) {
    cawParam.value.pageNum = pageNum
    getDataLists()
}
const router = useRouter();
const detial = (id:number) => {
    router.push(`/cifaItem/${id}`) 
}



</script>
<style scoped lang='less'>
.bg {
    background-color: #ffffff;
    overflow: auto;
}

.title {
    width: 1300px;
    margin: 0 auto;
    border-radius: 3px;
    text-align: left;
    padding-left: 45px;
    background-color: #F5F5F5;
    height: 45px;
    line-height: 45px;
    color: #000;

    span {
        margin: 0 15px;
        cursor: pointer;
    }
}

.content {
    width: 1300px;
    margin: 0 auto;
    padding: 20px 0;
    display: flex;
    justify-content: space-between;

    .left {
        width: calc(100% - 300px);

        >ul {
            >li {
                display: flex;
                padding: 40px 15px;
                border-bottom: 1px solid #d1cdd1;

                .time {
                    display: flex;
                    flex-direction: column;
                    width: 80px;

                    p {
                        position: relative;
                        font-size: 18px;
                        padding: 20px 0;

                    }

                    p:first-child {
                        height: fit-content;
                    }

                    p:last-child {
                        font-size: 46px;
                    }

                    p:first-child::after {
                        content: "";
                        position: absolute;
                        width: 50px;
                        height: 1px;
                        background-color: #d88e68;
                        bottom: 0;
                        left: -3px;
                    }
                }

                img {
                    width: 350px;
                    height: 200px;
                    margin-left: 10px;
                    margin-right: 50px;
                }

                .txt {
                    width: calc(100% - 500px);

                    ul {
                        li {
                            display: flex;
                            flex-direction: column;
                            height: 200px;
                            justify-content: space-around;

                            >p:first-child {
                                font-size: 18px;
                                font-weight: bold;
                            }

                            >p:nth-child(2) {
                                color: #747474;
                            }
                        }
                    }
                }
            }
        }
    }

    .right {
        width: 280px;
        max-height: 350px;
        overflow: auto;
        background: #F1F5F9;

        ul {
            padding-left: 30px;

            li {
                list-style: circle;
                padding: 7px 5px;
                cursor: pointer;
            }
        }
    }
}

.detial {
    width: 80px;
}

:deep(.el-pagination) {
    width: fit-content;
    margin: 0 auto 20px;
}
.aa{
    color: #252525cc;
    word-break: break-all;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
</style>